package com.jiang.demo.entity;

import com.jiang.demo.common.constans.Constant;
import com.jiang.demo.common.enums.GenderEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.time.LocalDate;
import java.util.List;

@ApiModel(value = "UserEntity")
@Data
@EqualsAndHashCode(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "user")
public class UserEntity extends BaseEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @ApiModelProperty("主键ID")
    private Long id;

    @NotBlank(message = "用户名不能为空")
    @ApiModelProperty("用户名")
    private String name;

    @ApiModelProperty("年龄")
    private int age;

    @Type(type = Constant.OBJECT_TYPE)
    @ApiModelProperty(value = "性别", notes = "com.jiang.demo.common.enums.GenderEnum")
    private GenderEnum gender;

    @Type(type = Constant.STRING_LIST_TYPE)
    @ApiModelProperty("标签")
    private List<String> tags;

    @Type(type = Constant.LONG_LIST_TYPE)
    @ApiModelProperty("标签ID")
    private List<Long> tagIds;

    @Type(type = Constant.OBJECT_TYPE)
    @ApiModelProperty("地址列表")
    private List<Address> addressList;

    @Type(type = Constant.OBJECT_TYPE)
    @ApiModelProperty("拓展信息")
    private Ext ext;

    @ApiModelProperty
    private LocalDate birth;


    @ApiModel(value = "Address")
    @Data
    public static class Address{

        @ApiModelProperty("id")
        private Long id;

        @ApiModelProperty("地址")
        private String address;
    }

    @ApiModel(value = "Ext")
    @Data
    public static class Ext{

        @ApiModelProperty("ext1")
        private String ext1;

        @ApiModelProperty("ext2")
        private String ext2;

        @ApiModelProperty("extList")
        private List<String> extList;
    }
}
